<template>
  <div class="head">
    <div class="tit">
      <button class="tex1">其他费用报表</button>
    </div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form
            ref="form"
            style="display: flex;flex-wrap: wrap;margin-top: 24px;justify-content: space-between;"
            :model="form"
            label-width="80px"
          >
            <div style="display: flex;justify-content: space-between;flex-wrap: wrap;" :style="{ width: height + 'px' }">
              <el-form-item class="text" label="费用科目">
                <el-select v-model="form.type" placeholder="请选择" style="width: 286px;" @change="changeType">
                  <el-option label="短驳费" value="1" />
                  <el-option label="二次中转费" value="2" />
                  <el-option label="大货操作费收" value="3" />
                  <el-option label="全网出港费" value="4" />
                  <el-option label="纸质面单操作费" value="5" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="结算中心">
                <el-select :disabled="true" placeholder="辽宁盘锦公司" style="width: 286px;">
                  <el-option label="辽宁盘锦公司" value="1" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="结算对象">
                <el-select v-model="form.transferCentreId" placeholder="请选择" style="width: 286px;">
                  <el-option
                    v-for="item in TransferCenterList"
                    :key="item.id"
                    class="input"
                    :label="item.transferCenter"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <el-form-item v-if="value1 === 1" class="text" label="目的中心">
                <el-select v-model="form.aimTransferCentreId" placeholder="请选择" style="width: 286px;">
                  <el-option
                    v-for="item in TransferCenterList"
                    :key="item.id"
                    class="input"
                    :label="item.transferCenter"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <!-- <el-form-item v-if="form.type === '3' || form.type === '4' || form.type === '5'" label-width="130px"
                class="text" label="结算对象汇总标志">
                <el-select v-model="form.transferCentreId" placeholder="请选择" style="width: 286px;">
                  <el-option v-for="item in TransferCenterList" :key="item.id" class="input" :label="item.transferCenter"
                    :value="item.id" />
                </el-select>
              </el-form-item> -->
            </div>
            <div>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button @click="khClear">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form
            ref="form"
            style="display: flex;justify-content: space-between;flex-wrap: wrap;"
            :model="form"
            label-width="80px"
          >
            <div style="display: flex;justify-content: space-between;flex-wrap: wrap;width: 1207px;">
              <el-form-item class="text" label="日期">
                <el-date-picker
                  v-model="value"
                  type="daterange"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  style="width: 708px"
                  @change="changeTime"
                />
              </el-form-item>
              <el-form-item v-if="value1 === 1" class="text" label="汇总标志">
                <el-select v-model="form.collectType" placeholder="请选择" style="width: 286px;">
                  <el-option label="结算中心" value="1" />
                  <el-option label="结算对象" value="2" />
                  <el-option label="结算中心+结算对象" value="3" />
                  <el-option label="结算中心+目的中心" value="4" />
                  <el-option label="结算中心+目的中心+结算对象" value="5  " />
                </el-select>
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button @click="onSubmit"><i class="el-icon-upload2" />导出</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <el-table
          v-if="form.type === '1' || form.type === '2' || form.type === ''"
          :data="tableData"
          border
          max-height="734"
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column type="index" width="50" :index="table_index" align="center" />
          <el-table-column prop="collectDate" label="时间段" width="180" align="center" />
          <el-table-column prop="networkNameId" label="结算中心编码" align="center" />
          <el-table-column prop="networkName.networkName" label="结算中心名称" align="center" />
          <el-table-column prop="recFee" label="应收费用" align="center" />
          <el-table-column prop="actRecFee" label="实收费用" align="center" />
          <el-table-column prop="recShipmentQty" label="应收票件量" align="center" />
          <el-table-column prop="recWeight" label="应收重量" align="center" />
          <el-table-column prop="payFee" label="应付费用" align="center" />
          <el-table-column prop="actPayFee" label="实付费用" align="center" />
          <el-table-column prop="payShipmentQty" label="应付票件量" align="center" />
          <el-table-column prop="payWeight" label="应付重量" align="center" />
        </el-table>
        <el-table
          v-if="form.type === '3' || form.type === '4' || form.type === '5'"
          :data="tableData"
          border
          max-height="734"
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column type="index" width="50" :index="table_index" align="center" />
          <el-table-column prop="collectDate" label="时间" width="180" align="center" />
          <el-table-column prop="networkNameId" label="结算网点编码" align="center" />
          <el-table-column prop="networkName.networkName" label="结算网点名称" align="center" />
          <el-table-column prop="totalNum" label="件量" align="center" />
          <el-table-column prop="totalAmount" label="费用" align="center" />
        </el-table>
        <div style="display: flex;justify-content: space-between;margin-top: 51px;">
          <div class="title2" />
          <div class="block" style="display: flex; justify-content: flex-end">
            <el-pagination
              background
              :current-page="current"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="10"
              layout="total, prev, pager, next"
              :total="+total"
              prev-text="上一页"
              next-text="下一页"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { TransferCenterApi, ShortBargeFeeApi, ShortBargeFeeApi1 } from '@/api/HqFinancePanel'

export default {

  components: {},
  data() {
    return {
      value: '',
      value1: 1,
      form: {
        aimTransferCentreId: '',
        collectType: '',
        endTime: '',
        networkNameId: '1',
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        startTime: '',
        transferCentreId: '',
        type: ''
      },
      height: 1630,
      tableData: [],
      current: '', // 页数
      pages: '', // 条数
      total: '', // 总数
      TransferCenterList: []// 转运中心列表

    }
  },

  computed: {},

  created() {
    this.TransferCenter()
  },

  methods: {
    // 序号
    table_index(index) {
      return (this.pages - 1) * this.current + index + 1
    },
    // 选择时间
    changeTime() {
      this.form.startTime = this.value[0]
      this.form.endTime = this.value[1]
    },
    // 上一页
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val
      this.onSubmit()
    },
    // 下一页
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val
      this.onSubmit()
    },
    // 转运中心列表
    async TransferCenter() {
      const res = await TransferCenterApi()
      this.TransferCenterList = res.data
    },
    // 重置
    khClear() {
      Object.keys(this.form).forEach((key) => {
        if (key !== 'pageDate' && key !== 'networkNameId') {
          this.form[key] = ''
        }
      })
      this.tableData = []
      this.value = ''
      this.total = ''
      this.current = ''
      this.pages = ''
    },
    changeType() {
      if (this.form.type === '1' || this.form.type === '2') {
        this.height = 1630
        this.value1 = 1
      } else if (this.form.type === '3' || this.form.type === '4' || this.form.type === '5') {
        this.height = 1210
        this.value1 = 2
      }
      this.tableData = []
      this.form.collectType = ''
      this.form.aimTransferCentreId = ''
    },
    table(res) {
      this.tableData = res.data.data
      this.total = res.data.total
      this.current = res.data.current
      this.pages = res.data.pages
    },
    // 查询
    async onSubmit() {
      const params = {}
      Object.keys(this.form).forEach(key => {
        if (this.form[key]) {
          params[key] = this.form[key]
        }
      })
      if (this.form.type == '1' || this.form.type == '2') {
        const res = await ShortBargeFeeApi(params)
        this.table(res)
      } else {
        const res = await ShortBargeFeeApi1(params)
        this.table(res)
      }
    }
  }
}

</script>
<style  scoped lang="scss">
.tit {
  display: flex;

  .tex1 {
    margin-right: 48px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
    background: #fff;
    border: 1px #fff solid;
  }

  .active {
    font-family: Source Han Sans CN;
    font-weight: 700;
    color: #2087D0;
    position: relative;

  }

  .active::before {
    position: absolute;
    content: '';
    width: 110px;
    height: 2px;
    background: #2087D0;
    border-radius: 1px;
    bottom: -20px;
    left: 50%;
    transform: translate(-50%);
  }
}

.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
  margin-top: 20px;
}

.line {
  height: 1px;
  background: #D8D8D8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    .input {
      width: 286px;
      height: 36px;
      background: #FFFFFF;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #FFFFFF;
      border: 1px solid #B4B4B4;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
